<?php
header("content-type:text/html;charset=utf8");
$dbh  = new  PDO ( 'mysql:host=localhost;dbname=mhsw' , 'root' , 'root' );
$sql='select * from jj';
$arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
//print_r($arr);die;
?>
<table border="1" align="center">
    <tr align="center">
        <td>编号</td>
        <td>用户名</td>
        <td>密码</td>
        <td>操作</td>
        <td>添加时间</td>
    </tr>
    <?php foreach($arr as $key=>$value) {  ?>
        <tr>
            <td><?php echo $value['id'];?></td>
            <td><?php echo $value['username'];?></td>
            <td><?php echo $value['userpwd'];?></td>
            <td>
                <a href="javascript:void(0);" onclick="del(<?php echo $value['id']; ?>,this)">删除</a>
                <a href="update.php?id=<?php echo $value['id']?>">修改</a>
                <a href="zhanshi.php?id=<?php echo $value['id']?>">查看页面内容</a>
                <a href="zhanshi.php?id=<?php echo $value['id']?>">静态化</a>
            </td>
            <td><?php echo $value['addtime'];?></td>
        </tr>
    <?php  }  ?>
</table>
<script type="text/javascript">
    function del(id,obj) {
        //alert(id);
        var ajax=new XMLHttpRequest();
        ajax.onreadystatechange=function()
        {
            if(ajax.readyState==4&&ajax.status==200)
            {
                //alert(ajax.responseText);
                if(ajax.responseText=='1')
                {
                     obj.parentNode.parentNode.remove();
//                    console.log(tr);
                }
                else
                {
                    alert('单个删除失败');
                }
            }
        }
        ajax.open('get','uu.php?id='+id,true);
        ajax.send();
   }
</script>